Skip to content

Prevent UAF on DER objects, reject API in SNI callback#10905

Open
padelsbach wants to merge 1 commit into
wolfSSL:masterfrom
padelsbach:reject-sni-and-refcnt-der
Open

Prevent UAF on DER objects, reject API in SNI callback#10905
padelsbach wants to merge 1 commit into
wolfSSL:masterfrom
padelsbach:reject-sni-and-refcnt-der

Conversation

@padelsbach

@padelsbach padelsbach commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a family of UAF due to shared DER buffer between WOLFSSL_CTX and WOLFSSL objects raised in zd 22107.

There are two situations we want to solve:

  1. Adjusting certs/keys in the SNI callback. Today this triggers a UAF, but even with a fix, does not apply the change for the active session. So this change disables those APIs.
  2. Reload certs/keys (outside of the SNI callback) on a live TLS session. Memcached and Mosquitto do this today via Openssl compat APIs (SSL_CTX_use_certificate_chain_file, SSL_CTX_use_PrivateKey_file, SSL_CTX_use_certificate)

Change is to refcount DER objects and disallow several routines from the SNI callback.

Footprint impact:

  • refcount disabled (embedded): none
  • refcount enabled w/ atomics: none (fits into padding)
  • refcount enabled w/ mutex: +56 bytes

The following APIs are not allowed during the SNI callback:

Certificate:

wolfSSL_CTX_use_certificate_file
wolfSSL_CTX_use_certificate_buffer
wolfSSL_CTX_use_certificate_ASN1
wolfSSL_CTX_use_certificate (X509)
wolfSSL_CTX_use_certificate_label (WOLF_CRYPTO_CB)
wolfSSL_CTX_use_certificate_id (WOLF_CRYPTO_CB)

Certificate chain:

wolfSSL_CTX_use_certificate_chain_file
wolfSSL_CTX_use_certificate_chain_file_format
wolfSSL_CTX_use_certificate_chain_buffer
wolfSSL_CTX_use_certificate_chain_buffer_format
wolfSSL_CTX_add_extra_chain_cert
wolfSSL_CTX_add0_chain_cert
wolfSSL_CTX_add1_chain_cert
wolfSSL_CTX_ctrl (cases SSL_CTRL_CHAIN and SSL_CTRL_EXTRA_CHAIN_CERT)

Private key:

wolfSSL_CTX_use_PrivateKey_file
wolfSSL_CTX_use_PrivateKey_buffer
wolfSSL_CTX_use_PrivateKey_ASN1
wolfSSL_CTX_use_PrivateKey (EVP_PKEY)
wolfSSL_CTX_use_RSAPrivateKey
wolfSSL_CTX_use_RSAPrivateKey_file (delegates to use_PrivateKey_file)
wolfSSL_CTX_use_PrivateKey_Id (WOLF_PRIVATE_KEY_ID)
wolfSSL_CTX_use_PrivateKey_Id_ex (delegates to _Id)
wolfSSL_CTX_use_PrivateKey_Label (WOLF_PRIVATE_KEY_ID)

Alt private key (WOLFSSL_DUAL_ALG_CERTS):

wolfSSL_CTX_use_AltPrivateKey_file
wolfSSL_CTX_use_AltPrivateKey_buffer
wolfSSL_CTX_use_AltPrivateKey_Id
wolfSSL_CTX_use_AltPrivateKey_Id_ex (delegates to _Id)
wolfSSL_CTX_use_AltPrivateKey_Label

The following APIs are not allowed while any session is active since the DH params buffer is public and thus cannot be refcounted without breaking the ABI.

DH:

wolfSSL_CTX_SetTmpDH
wolfSSL_CTX_SetTmpDH_buffer
wolfSSL_CTX_SetTmpDH_file
wolfSSL_CTX_set_tmp_dh (OpenSSL-compat, WOLFSSL_DH*)

Testing

Added unit tests.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@padelsbach padelsbach force-pushed the reject-sni-and-refcnt-der branch from ef8b88b to 767782b Compare July 15, 2026 04:19
@padelsbach padelsbach force-pushed the reject-sni-and-refcnt-der branch from 767782b to c432e9e Compare July 15, 2026 13:53
@padelsbach padelsbach marked this pull request as ready for review July 15, 2026 13:54
@github-actions

Copy link
Copy Markdown

retest this please

@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m0plus

  • FLASH: .text +4 B (+0.0%, 64,187 B / 262,144 B, total: 24% used)

gcc-arm-cortex-m3

  • FLASH: .text +156 B (+0.1%, 122,661 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +57 B, .text +192 B (+0.1%, 200,633 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +64 B (+0.0%, 174,632 B / 262,144 B, total: 67% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +128 B (+0.1%, 181,080 B / 1,048,576 B, total: 17% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +64 B, .text +192 B (+0.0%, 771,468 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m4-pq

  • FLASH: .rodata +56 B, .text +192 B (+0.1%, 279,708 B / 1,048,576 B, total: 27% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .rodata +64 B, .text +192 B (+0.1%, 325,376 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +128 B (+0.1%, 123,405 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +57 B, .text +256 B (+0.1%, 236,459 B / 262,144 B, total: 90% used)

gcc-arm-cortex-m7

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +57 B, .text +192 B (+0.1%, 200,569 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m7-pq

  • FLASH: .rodata +56 B, .text +192 B (+0.1%, 280,284 B / 1,048,576 B, total: 27% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +57 B, .text +192 B (+0.1%, 236,459 B / 262,144 B, total: 90% used)

linuxkm-pie

  • Data: __patchable_function_entries +8 B (+0.0%, 25,568 B)

linuxkm-standard

@padelsbach

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants